/*****************************************************************************/
/**
 *  @file   OverView.cpp
 *  @author Naohisa Sakamoto
 */
/*----------------------------------------------------------------------------
 *
 *  Copyright (c) Visualization Laboratory, Kyoto University.
 *  All rights reserved.
 *  See http://www.viz.media.kyoto-u.ac.jp/kvs/copyright/ for details.
 *
 *  $Id: OverView.cpp 83 2013-12-18 16:02:33Z naohisa.sakamoto $
 */
/*****************************************************************************/
#include "OverView.h"
#include "Util.h"
#include <kvs/glut/Application>
#include <kvs/glut/Screen>
#include <kvs/RGBColor>
#include <kvs/LineObject>
#include <kvs/LineRenderer>
#include <kvs/Bounds>
#include <kvs/ObjectManager>
#include <kvs/RendererManager>
#include <kvs/IDManager>


OverView::OverView( kvs::glut::Application* app ):
    kvs::glut::Screen( app ),
    m_data_set( 0 ),
    m_resource_monitor( 0 )
{
    setTitle( "Over view" );
    setBackgroundColor( kvs::RGBColor::White() );
}

void OverView::attachDataSet( DataSet* data_set )
{
    m_data_set = data_set;
}

void OverView::attachResourceMonitor( ResourceMonitor* resource_monitor )
{
    m_resource_monitor = resource_monitor;
}

void OverView::loadObject()
{
    if ( m_data_set->volume() )
    {
        kvs::LineRenderer* renderer = new kvs::LineRenderer();
        renderer->enableAntiAliasing();

        kvs::Bounds global_bounds;
        global_bounds.setLineWidth( 2.0f );
        global_bounds.setLineColor( kvs::RGBColor::Black() );
        registerObject( global_bounds.outputLineObject( m_data_set->volume().get() ), renderer );

        const size_t nbounds = m_data_set->bounds().ranges.size();
        for ( size_t i = 0; i < nbounds; i++ )
        {
            const kvs::Vec3 min_obj = m_data_set->bounds().ranges[i].min;
            const kvs::Vec3 max_obj = m_data_set->bounds().ranges[i].max;

            kvs::PointObject dummy;
            dummy.setMinMaxObjectCoords( min_obj, max_obj );
            dummy.setMinMaxExternalCoords( min_obj, max_obj );

            kvs::Bounds local_bounds;
            local_bounds.setLineWidth( 1.0f );
            local_bounds.setLineColor( kvs::RGBColor::Black() );
            registerObject( local_bounds.outputLineObject( &dummy ), renderer );
        }
    }
}
